package com.feibi.study.Utils;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

/**
 * 权限获取类
 * Created by baorui on 2017/7/24.
 */

public class PermissionsGetter {

    public static String[] meidaPermission = {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA,Manifest.permission.RECORD_AUDIO};
    public static String[] cameraPermission = {Manifest.permission.CAMERA};


    /**
     * 判断权限集合
     * permissions 权限数组
     * return true-表示没有权限  false-表示权限已开启
     */
    public static boolean lacksPermissions(Activity activity, String[] permission) {
        for (String p : permission) {
            if (lacksPermission(activity, p)) {
                ActivityCompat.requestPermissions(activity, permission, 0);
                return true;
            }
        }
        return false;
    }

    /**
     * 判断是否缺少权限
     */
    private static boolean lacksPermission(Context mContexts, String permission) {
        return ContextCompat.checkSelfPermission(mContexts, permission) ==
                PackageManager.PERMISSION_DENIED;
    }

    /**
     * 判断是否缺少权限
     */
    public static void CheckStorageAndCameraPermission(Activity activity) {
        lacksPermissions(activity, meidaPermission);
    }

}
